function deepClone(obj, weakmap = new WeakMap()) {
    if(typeof obj !== 'object' && obj === null) {
        return obj
    }
    const newObj = new obj.constructor()
    if(!weakmap.has(obj)) {
        weakmap.set(obj, newObj)
    }
    else {
        return weakmap.get(obj)
    }
    for(let i in obj) {
        if(obj.hasOwnProperty(i)) {
            newObj[i] = obj[i] instanceof Object ? deepClone(obj[i], weakmap) : obj[i]
        }
    }
    return newObj
}

const obj = {
    name:'csc',
    age:18
}
obj.a = obj
console.log(obj);
const newObj = deepClone(obj)
console.log(newObj);